package org.dromara.oce.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.oce.service.CompilePeopleRecordService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.oce.domain.vo.CompilePeopleRecordVo;
import org.dromara.oce.domain.bo.CompilePeopleRecordBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 编辑人员
 *
 * @author Lion Li
 * @date 2025-02-26
 * @module 管理平台接口
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oce/peopleRecord")
public class CompilePeopleRecordController extends BaseController {

    private final CompilePeopleRecordService compilePeopleRecordService;

    /**
     * 查询编辑人员列表
     */
    @SaCheckPermission("oce:peopleRecord:list")
    @GetMapping("/list")
    public TableDataInfo<CompilePeopleRecordVo> list(CompilePeopleRecordBo bo, PageQuery pageQuery) {
        return compilePeopleRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取编辑人员详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("oce:peopleRecord:query")
    @GetMapping("/{id}")
    public R<CompilePeopleRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(compilePeopleRecordService.queryById(id));
    }

    /**
     * 新增编辑人员
     */
    @SaCheckPermission("oce:peopleRecord:add")
    @Log(title = "编辑人员", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CompilePeopleRecordBo bo) {
        return toAjax(compilePeopleRecordService.insertByBo(bo));
    }

    /**
     * 修改编辑人员
     */
    @SaCheckPermission("oce:peopleRecord:edit")
    @Log(title = "编辑人员", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CompilePeopleRecordBo bo) {
        return toAjax(compilePeopleRecordService.updateByBo(bo));
    }

    /**
     * 删除编辑人员
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oce:peopleRecord:remove")
    @Log(title = "编辑人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(compilePeopleRecordService.deleteWithValidByIds(List.of(ids), true));
    }
}
